package com.fxhy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fxhy.bean.custom.AgentUserCustom;
import com.fxhy.bean.custom.MyInviteCustom;
import com.fxhy.contants.Constants;
import com.fxhy.service.InviteUserInfoService;
import com.fxhy.service.UserService;
import com.fxhy.vo.ResponseBodyEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@RestController
@Api(value="邀请关系接口")
@RequestMapping("user")
public class InviteUserApi {
	@Autowired
	private UserService userService;
	
	@Autowired
	private InviteUserInfoService inviteUserInfoService;
	
	/**
	 * 修改用户信息
	 * @return
	 */
	@ApiOperation("查找我的邀请好友")
	@RequestMapping(value="findInviteUser",method= {RequestMethod.GET,RequestMethod.POST})
	public ResponseBodyEntity findInviteUser(String phoneNum,String token){
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		
		AgentUserCustom user = userService.findCustomByPhoneNum(phoneNum);
		if(user != null){
			if(user.getIsIdentifi() > 0){
				responseBodyEntity.setData(inviteUserInfoService.findInviteUser(user));
				responseBodyEntity.setMsg("查询成功!");
				responseBodyEntity.setState(Constants.SUCCEED);
			}else{
				responseBodyEntity.setData("/login");
				responseBodyEntity.setMsg("未发现你完成认证信息!为了避免信息泄露!请重新登录!");
				responseBodyEntity.setState(Constants.FAILURE);
				return responseBodyEntity;
			}
		}else{
			responseBodyEntity.setData("/login");
			responseBodyEntity.setMsg("登陆失效!为了避免信息泄露!请重新登录!");
			responseBodyEntity.setState(Constants.FAILURE);
			return responseBodyEntity;
		}
		return responseBodyEntity;
	}
}
